package com.example.factory.core.domain;


import org.apache.commons.collections4.CollectionUtils;

import javax.persistence.*;
import java.util.List;

/**
 * @author Lei Tao
 */
@Entity
@Table(name = "equipment")

public class Equipment extends DomainObject {
    private String name;

    /**
     * 设备类型
     */
    @Column(name = "equipment_type")
    private String equipmentType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "department_id")
    private Department department;

    @OneToMany(mappedBy="equipment",fetch = FetchType.LAZY,orphanRemoval = true)
    private List<ReportEquipment> reportEquipments;

    public Equipment() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEquipmentType() {
        return equipmentType;
    }

    public void setEquipmentType(String equipmentType) {
        this.equipmentType = equipmentType;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public ReportEquipment getReportEquipments() {
        if (CollectionUtils.isEmpty(this.reportEquipments)){
            return null;
        }
        return reportEquipments.get(0);
    }

    public void setReportEquipments(ReportEquipment reportEquipments) {
        this.reportEquipments.add(reportEquipments);
    }
}
